home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / newmat03.lha / newmat03 / newmatrc.hxx < prev    next >
Text File  |  1993-08-08  |  5KB  |  110 lines

  1. //$$ newmatrc.hxx            definition file for row/column classes
  2.  
  3. // Copyright (C) 1991: R B Davies and DSIR
  4.  
  5. #ifndef MATRIXRC_LIB
  6. #define MATRIXRC_LIB 0
  7.  
  8. #include "controlw.hxx"
  9.  
  10.  
  11.  
  12. /************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
  13.  
  14. // Used for accessing the rows and columns of matrices
  15. // All matrix classes must provide routines for calculating matrix rows and
  16. // columns. Assume rows can be found very efficiently.
  17.  
  18. enum { LoadOnEntry=1,StoreOnExit=2,IsACopy=4,DirectPart=8,StoreHere=16 };
  19.  
  20. class MatrixRowCol
  21. // the row or column of a matrix
  22. {
  23. public:                                        // these are public to avoid
  24.                                                // numerous friend statements
  25.    int length;                                 // row or column length
  26.    int skip;                                   // initial number of zeros
  27.    int storage;                                // number of stored elements
  28.    int rowcol;                                 // row or column number
  29.    GeneralMatrix* gm;                          // pointer to parent matrix
  30.    real* store;                                // pointer to local storage
  31.                                                //    less skip
  32.    ControlWord cw;                             // Load? Store? Is a Copy?
  33.    void IncrMat() { rowcol++; store += storage; }
  34.                                                // used by NextRow
  35.    void IncrDiag() { rowcol++; skip++; }
  36.    void IncrUT() { rowcol++; storage--; store += storage; skip++; }
  37.    void IncrLT() { rowcol++; store += storage; storage++; }
  38.  
  39. public:
  40.    void Add(const MatrixRowCol&);              // add a row/col
  41.    void AddScaled(const MatrixRowCol&, real);  // add a multiple of a row/col
  42.    void Add(const MatrixRowCol&, const MatrixRowCol&);
  43.                                                // add two rows/cols
  44.    void Add(const MatrixRowCol&, real);        // add a row/col
  45.    void Sub(const MatrixRowCol&);              // subtract a row/col
  46.    void Sub(const MatrixRowCol&, const MatrixRowCol&);
  47.                                                // sub a row/col from another
  48.    void RevSub(const MatrixRowCol&);           // subtract from a row/col
  49.    void Copy(const MatrixRowCol&);             // copy a row/col
  50.    void Copy(const real*&);                    // copy from an array
  51.    void Copy(real);                            // copy from constant
  52.    real SumAbsoluteValue();                    // sum of absolute values
  53.    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
  54.    void Negate(const MatrixRowCol&);           // change sign of a row/col
  55.    void Multiply(const MatrixRowCol&, real);   // scale a row/col
  56.    friend real DotProd(const MatrixRowCol&, const MatrixRowCol&);
  57.                                                // sum of pairwise product
  58.    real* operator()() { return store+skip; }   // pointer to first element
  59.    real* Store() { return store; }
  60.    int Skip() { return skip; }                 // number of elements skipped
  61.    int Storage() { return storage; }           // number of elements stored
  62.    void Skip(int i) { skip=i; }
  63.    void Storage(int i) { storage=i; }
  64.    void SubRowCol(MatrixRowCol&, int, int) const;
  65.                                                // get part of a row or column
  66.    MatrixRowCol() {}                           // to stop warning messages
  67.    virtual ~MatrixRowCol();
  68. };
  69.  
  70. class MatrixRow : public MatrixRowCol
  71. {
  72. public:
  73.    // bodies for these are inline at the end of this hxx file
  74.    MatrixRow(GeneralMatrix*, ControlWord, int=0);
  75.                                                // extract a row
  76.    ~MatrixRow();
  77.    void Next();                                // get next row
  78. };
  79.  
  80. class MatrixCol : public MatrixRowCol
  81. {
  82. public:
  83.    // bodies for these are inline at the end of this hxx file
  84.    MatrixCol(GeneralMatrix*, ControlWord, int=0);
  85.                                                // extract a col
  86.    MatrixCol(GeneralMatrix*, real*, ControlWord, int=0);
  87.                                                // store/retrieve a col
  88.    ~MatrixCol();
  89.    void Next();                                // get next row
  90. };
  91.  
  92.  
  93. /**************************** inline bodies ****************************/
  94.  
  95. inline MatrixRow::MatrixRow(GeneralMatrix* gmx, ControlWord cwx, int row)
  96. { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); } 
  97.  
  98. inline void MatrixRow::Next() { gm->NextRow(*this); }
  99.  
  100. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, ControlWord cwx, int col)
  101. { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); } 
  102.  
  103. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, real* r,
  104.    ControlWord cwx, int col)
  105. { gm=gmx; store=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); } 
  106.  
  107. inline void MatrixCol::Next() { gm->NextCol(*this); }
  108.  
  109. #endif
  110.